// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {
    ccclass,
    property
} = cc._decorator;
import {
    Gardener,
    GardenerWindow,
    IGardenerWindow
} from "../gardener/GameGardener"

@ccclass
export default class TreeInfoWindow extends GardenerWindow implements IGardenerWindow {


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {

        let animeNode: cc.Node = new cc.Node();
        animeNode.setPosition(0, -Gardener.stageHeight * .5);
        this.node.addChild(animeNode);
        Gardener.dragonbonesGenerateAnime(animeNode, 'anime/tree', 'Armature', (animeComponent: dragonBones.ArmatureDisplay, err:any) => {
            if (err) {
                animeNode.destroy();
            } else {
                this.scheduleOnce(()=>{
                    animeComponent.playAnimation('newAnimation', 0);
                }, 1);
            }
        });
    };

    // update (dt) {},

    onBtnClose_Tap() {
        Gardener.closeWindow();
    };

    onBtnAnime_Tap() {
        let animeNode: cc.Node = new cc.Node();
        animeNode.setPosition(CommonUtils.getRandomInteger(500, -500), CommonUtils.getRandomInteger(300, -300));
        this.node.addChild(animeNode);
        Gardener.dragonbonesGenerateAnime(animeNode, 'anime/db_001', 'db_mcy_03000006', (animeComponent, err) => {
            if (err) {
                animeNode.destroy();
            } else {
                animeComponent.playAnimation('action_3', 2);
            }
        });
    }

    display() {
        GameLogger.debug('tree window display');
    };

    dispose() {
        GameLogger.debug('tree window dispose');
    }
};